package com.rising.face.ali.xianliu;

public class Test1 {
    //漏桶：水滴的漏出速率是每秒 1 滴
    private static LeakyBucket leakyBucket = new LeakyBucket(1);

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            // 1.限流判断
            boolean acquire = leakyBucket.acquire();
            if (!acquire) {
                System.out.println("稍后再试！");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            } else {
                System.out.println("获取到令牌");
            }
            // 2.如果没有达到限流的要求,直接调用接口查询
        }
    }
}
